//ok
namespace hjc {

	export abstract class BaseUI extends eui.Component implements UIComponent {

		protected content: eui.Component | eui.Group;
		protected abstract _init(): void;
		protected abstract _created(): void;

		constructor() {
			super();
			if (isFunc(this._init)) this._init();
		}

		protected createChildren() {
			super.createChildren();
			if (!this.content) this.content = this;
			if (isFunc(this._created)) this._created();
		}

		public setVisible(visible: boolean): UIComponent { this.visible = visible; return this; }

		public setAlpha(alpha: number): UIComponent { this.alpha = alpha; return this; }

		public setInLayout(inlayout: boolean): UIComponent { this.includeInLayout = inlayout; return this; }

		public setEnabled(enabled: boolean): UIComponent {
			if (this.enabled === enabled) return this;
			this.enabled = enabled;
			this.enabled ? effect.removeColor(this) : effect.toGray(this);
			this.invalidateState();
			return this;
		}

		public addContent(obj: egret.DisplayObject, options?: hjc.DisplayOptions): BaseUI {
			ui.setDisplay(obj, options, this.content);
			return this;
		}

		protected getCurrentState(): string {
			return this.enabled ? hjc.Skin.State.UP : hjc.Skin.State.DISABLED;
		}

	}
}